﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Windows.Forms;

#endregion
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting;
using System.IO;
using Thinxoft.HttpLib;
using System.Threading;
using System.Collections.Specialized;
using System.Runtime.Remoting.Lifetime;
using System.Net.Sockets;
using System.Net;
using System.Runtime.Serialization.Formatters.Binary;

namespace HTTPReqMan
{

    


    static class Program
    {

        static ServerState xstate;
        static Settings xsettings;
        
        

        internal static void LoadSettings()
        {
            xsettings = new Settings();
            xstate = new ServerState();
            xstate.LoadSettings(ref xsettings);
            
        }

        public static ServerState XState
        {
            get
            {
                return xstate;
            }
        }

       
        [STAThread]
        static void Main()
        {
            try
            {
                LoadSettings();
                Monitor.StartMonitor(xstate);
                
                
                
                string name = "rh" + System.Diagnostics.Process.GetCurrentProcess().Id;
                //publish request handler
                IpcChannel channel = new IpcChannel("RequestHandlerInstance_" + name);

                ChannelServices.RegisterChannel(channel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(RequestHandler), name, WellKnownObjectMode.SingleCall);
                Application.Run();
                
            }
            catch (Exception ex)
            {
                ServerState.Log("In ReqManager-{0}:{1}",ex.Message,ex.StackTrace);
            }
            
        }
    }
}